package aynu.hd.Hotel.Controller;

import aynu.hd.Hotel.Service.roomService;
import aynu.hd.pojo.Room;
import aynu.hd.pojo.Schedule;
import aynu.hd.pojo.User;
import aynu.hd.pojo.v_room_info;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 系统主页跳转
 */
@Controller
@RequestMapping("hotel")
public class hotelController {
    @Autowired
    roomService roomService;

    //首页
    @GetMapping("index")
    public String index(Model model) {
        //豪华客房收藏最多的房间
        List<Room> roomList = roomService.queryRoomByCollect();
        model.addAttribute("roomList",roomList);
        //收藏最多的房间
        List<Room> roomList1 = roomService.queryRoomByCollect1();
        model.addAttribute("roomList1",roomList1);
        //销售最多的房间
        List<v_room_info> v_room_infoList = roomService.queryRoomByCollect2();
        model.addAttribute("v_room_infoList",v_room_infoList);
        return "hotel/index/index";
    }

    //关于我们
    @GetMapping("about_us")
    public String about_us() {
        return "hotel/about/about-us";
    }

    //预定房间
    @GetMapping("schedule")
    public String schedule(String roomType, Model model, @RequestParam(defaultValue = "1") Integer pageNum) {
        if (roomType == null) {
            roomType = "";
        }
        PageHelper.startPage(pageNum, 3);
        List<Room> roomList = roomService.queryRoomByType(roomType);
        //把查询结果放里面就可以了
        PageInfo<Room> pageInfo = new PageInfo<>(roomList);
        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("roomType", roomType);
        return "hotel/room/schedule";
    }

    //我的收藏(房间)
    @GetMapping("environment")
    public String environment(HttpSession session, Model model) {
        User user = (User) session.getAttribute("user");
        List<Room> roomList = roomService.environment(user);
        model.addAttribute("roomList",roomList);
        return "hotel/collect/surrounding";
    }

    //查看预定房间
    @GetMapping("schedule_room")
    public String schedule_room(HttpSession session, Model model) {
        User user = (User) session.getAttribute("user");
        List<Schedule> schedules = roomService.queryScheduleRoom(user);
        model.addAttribute("schedules",schedules);
        return "hotel/reserve/schedule_room";
    }

    //查看订单信息
    @GetMapping("orderInformation")
    public String orderInformation() {
        return "redirect:/order/orderList";
    }

    //搜索
    @GetMapping("search")
    public String search() {
        return "hotel/search";
    }

    //修改个人信息
    @GetMapping("modifyUser")
    public String modify_user(){
        return "hotel/user/modify_user";
    }
}
